//
//  NBStatus.swift
//  NBSinaWeibo
//
//  Created by ac on 16/5/24.
//  Copyright © 2016年 ac. All rights reserved.
//

import Foundation

class NBStatus: NSObject {
    //自动匹配机型对应的平台
    //4 4s 5 5c 都是32的
    //之后的都是 64位
    var id: Int64 = 0
    ///微博信息内容
    var text: String?
    ///微博创建时间
    var created_at: String?
    ///微博来源
    var source: String?
    //用户  直接赋值 会给自定义对象赋值一个字典
    //转发的数量
    var reposts_count: Int = 0
    //评论
    var comments_count: Int = 0
    //赞
    var attitudes_count: Int = 0
    
    
    var user: NBUser?
    
    var retweeted_status: NBStatus?
    
    var pic_urls: [NBPicture]?
    

    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            
            if let dict = value as? [String:AnyObject]{
                user = NBUser(dict:dict)
            }
            
            return
        }
        
        if key == "retweeted_status" {
            
            if let dict = value as? [String:AnyObject]{
                retweeted_status = NBStatus(dict:dict)
            }
            
            return
        }
        
        if key == "pic_urls" {
            
            if let arr = value as? [[String:AnyObject]]{
                var tempArr = [NBPicture]()
                for dict in arr {
                    let picture = NBPicture(dict: dict)
                    tempArr.append(picture)
                }
                
                pic_urls = tempArr
            }
            
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
